package com.hegaoye.ctrl;

import com.hegaoye.mqhandler.KafkaSender;
import com.hegaoye.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/account")
public class AccountCtrl {

  @Autowired
  AccountService accountService;
  @Resource
  private KafkaSender kafkaSender;

  @GetMapping(value = "/load")
  @ResponseBody
  public String load() {
    String result = accountService.load();
    return result;
  }

  @GetMapping(value = "/confirm")
  @ResponseBody
  public String confirm(String text) {
    kafkaSender.send(text);
    return "confirm_ok";
  }

  @PostMapping(value = "/build", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
  @ResponseBody
  public String build(String order) {
    accountService.save(order);
    return order;
  }
}
